<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Paperclip::Geometry</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Paperclip::Geometry</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/paperclip/lib/paperclip/geometry_rb.html">
                vendor/plugins/paperclip/lib/paperclip/geometry.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Defines the geometry of an image.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000101">aspect</a>&nbsp;&nbsp;
      <a href="#M000096">from_file</a>&nbsp;&nbsp;
      <a href="#M000099">horizontal?</a>&nbsp;&nbsp;
      <a href="#M000105">inspect</a>&nbsp;&nbsp;
      <a href="#M000102">larger</a>&nbsp;&nbsp;
      <a href="#M000095">new</a>&nbsp;&nbsp;
      <a href="#M000097">parse</a>&nbsp;&nbsp;
      <a href="#M000103">smaller</a>&nbsp;&nbsp;
      <a href="#M000098">square?</a>&nbsp;&nbsp;
      <a href="#M000104">to_s</a>&nbsp;&nbsp;
      <a href="#M000106">transformation_to</a>&nbsp;&nbsp;
      <a href="#M000100">vertical?</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">height</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">modifier</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">width</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000096" class="method-detail">
        <a name="M000096"></a>

        <div class="method-heading">
          <a href="#M000096" class="method-signature">
          <span class="method-name">from_file</span><span class="method-args">(file)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Uses ImageMagick to determing the dimensions of a file, passed in as either
a File or path.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000096-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000096-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 16</span>
16:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">from_file</span> <span class="ruby-identifier">file</span>
17:       <span class="ruby-identifier">file</span> = <span class="ruby-identifier">file</span>.<span class="ruby-identifier">path</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">&quot;path&quot;</span>
18:       <span class="ruby-identifier">geometry</span> = <span class="ruby-keyword kw">begin</span>
19:                    <span class="ruby-constant">Paperclip</span>.<span class="ruby-identifier">run</span>(<span class="ruby-value str">&quot;identify&quot;</span>, <span class="ruby-node">%Q[-format &quot;%wx%h&quot; &quot;#{file}&quot;[0]]</span>)
20:                  <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">PaperclipCommandLineError</span>
21:                    <span class="ruby-value str">&quot;&quot;</span>
22:                  <span class="ruby-keyword kw">end</span>
23:       <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">geometry</span>) <span class="ruby-operator">||</span>
24:         <span class="ruby-identifier">raise</span>(<span class="ruby-constant">NotIdentifiedByImageMagickError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{file} is not recognized by the 'identify' command.&quot;</span>))
25:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000095" class="method-detail">
        <a name="M000095"></a>

        <div class="method-heading">
          <a href="#M000095" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(width = nil, height = nil, modifier = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gives a <a href="Geometry.html">Geometry</a> representing the given height
and width
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000095-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000095-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 8</span>
 8:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">width</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">height</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">modifier</span> = <span class="ruby-keyword kw">nil</span>
 9:       <span class="ruby-ivar">@height</span> = <span class="ruby-identifier">height</span>.<span class="ruby-identifier">to_f</span>
10:       <span class="ruby-ivar">@width</span>  = <span class="ruby-identifier">width</span>.<span class="ruby-identifier">to_f</span>
11:       <span class="ruby-ivar">@modifier</span> = <span class="ruby-identifier">modifier</span>
12:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000097" class="method-detail">
        <a name="M000097"></a>

        <div class="method-heading">
          <a href="#M000097" class="method-signature">
          <span class="method-name">parse</span><span class="method-args">(string)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Parses a &quot;WxH&quot; formatted string, where W is the width and H is
the height.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000097-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000097-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 28</span>
28:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">string</span>
29:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">match</span> = (<span class="ruby-identifier">string</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/\b(\d*)x?(\d*)\b([\&gt;\&lt;\#\@\%^!])?/i</span>))
30:         <span class="ruby-constant">Geometry</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">match</span>[<span class="ruby-value">1</span>,<span class="ruby-value">3</span>])
31:       <span class="ruby-keyword kw">end</span>
32:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000101" class="method-detail">
        <a name="M000101"></a>

        <div class="method-heading">
          <a href="#M000101" class="method-signature">
          <span class="method-name">aspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The <a href="Geometry.html#M000101">aspect</a> ratio of the dimensions.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000101-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000101-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 50</span>
50:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">aspect</span>
51:       <span class="ruby-identifier">width</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">height</span>
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000099" class="method-detail">
        <a name="M000099"></a>

        <div class="method-heading">
          <a href="#M000099" class="method-signature">
          <span class="method-name">horizontal?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if the dimensions represent a horizontal rectangle
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000099-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000099-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 40</span>
40:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">horizontal?</span>
41:       <span class="ruby-identifier">height</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">width</span>
42:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000105" class="method-detail">
        <a name="M000105"></a>

        <div class="method-heading">
          <a href="#M000105" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Same as <a href="Geometry.html#M000104">to_s</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000105-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000105-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 74</span>
74:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
75:       <span class="ruby-identifier">to_s</span>
76:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000102" class="method-detail">
        <a name="M000102"></a>

        <div class="method-heading">
          <a href="#M000102" class="method-signature">
          <span class="method-name">larger</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Geometry.html#M000102">larger</a> of the two
dimensions
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000102-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000102-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 55</span>
55:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">larger</span>
56:       [<span class="ruby-identifier">height</span>, <span class="ruby-identifier">width</span>].<span class="ruby-identifier">max</span>
57:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000103" class="method-detail">
        <a name="M000103"></a>

        <div class="method-heading">
          <a href="#M000103" class="method-signature">
          <span class="method-name">smaller</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Geometry.html#M000103">smaller</a> of the two
dimensions
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000103-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000103-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 60</span>
60:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">smaller</span>
61:       [<span class="ruby-identifier">height</span>, <span class="ruby-identifier">width</span>].<span class="ruby-identifier">min</span>
62:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000098" class="method-detail">
        <a name="M000098"></a>

        <div class="method-heading">
          <a href="#M000098" class="method-signature">
          <span class="method-name">square?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if the dimensions represent a square
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000098-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000098-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 35</span>
35:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">square?</span>
36:       <span class="ruby-identifier">height</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">width</span>
37:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000104" class="method-detail">
        <a name="M000104"></a>

        <div class="method-heading">
          <a href="#M000104" class="method-signature">
          <span class="method-name">to_s</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the width and height in a format suitable to be passed to <a
href="Geometry.html#M000097">Geometry.parse</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000104-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000104-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 65</span>
65:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
66:       <span class="ruby-identifier">s</span> = <span class="ruby-value str">&quot;&quot;</span>
67:       <span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">width</span>.<span class="ruby-identifier">to_i</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">width</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
68:       <span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;x#{height.to_i}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">height</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
69:       <span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">modifier</span>.<span class="ruby-identifier">to_s</span>
70:       <span class="ruby-identifier">s</span>
71:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000106" class="method-detail">
        <a name="M000106"></a>

        <div class="method-heading">
          <a href="#M000106" class="method-signature">
          <span class="method-name">transformation_to</span><span class="method-args">(dst, crop = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the scaling and cropping geometries (in string-based ImageMagick
format) neccessary to transform this <a href="Geometry.html">Geometry</a>
into the <a href="Geometry.html">Geometry</a> given. If crop is true, then
it is assumed the destination <a href="Geometry.html">Geometry</a> will be
the exact final resolution. In this case, the source <a
href="Geometry.html">Geometry</a> is scaled so that an image containing the
destination <a href="Geometry.html">Geometry</a> would be completely filled
by the source image, and any overhanging image would be cropped. Useful for
square thumbnail images. The cropping is weighted at the center of the <a
href="Geometry.html">Geometry</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000106-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000106-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 85</span>
85:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">transformation_to</span> <span class="ruby-identifier">dst</span>, <span class="ruby-identifier">crop</span> = <span class="ruby-keyword kw">false</span>
86:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">crop</span>
87:         <span class="ruby-identifier">ratio</span> = <span class="ruby-constant">Geometry</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">dst</span>.<span class="ruby-identifier">width</span> <span class="ruby-operator">/</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">width</span>, <span class="ruby-identifier">dst</span>.<span class="ruby-identifier">height</span> <span class="ruby-operator">/</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">height</span> )
88:         <span class="ruby-identifier">scale_geometry</span>, <span class="ruby-identifier">scale</span> = <span class="ruby-identifier">scaling</span>(<span class="ruby-identifier">dst</span>, <span class="ruby-identifier">ratio</span>)
89:         <span class="ruby-identifier">crop_geometry</span>         = <span class="ruby-identifier">cropping</span>(<span class="ruby-identifier">dst</span>, <span class="ruby-identifier">ratio</span>, <span class="ruby-identifier">scale</span>)
90:       <span class="ruby-keyword kw">else</span>
91:         <span class="ruby-identifier">scale_geometry</span>        = <span class="ruby-identifier">dst</span>.<span class="ruby-identifier">to_s</span>
92:       <span class="ruby-keyword kw">end</span>
93: 
94:       [ <span class="ruby-identifier">scale_geometry</span>, <span class="ruby-identifier">crop_geometry</span> ]
95:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000100" class="method-detail">
        <a name="M000100"></a>

        <div class="method-heading">
          <a href="#M000100" class="method-signature">
          <span class="method-name">vertical?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if the dimensions represent a vertical rectangle
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000100-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000100-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/geometry.rb, line 45</span>
45:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">vertical?</span>
46:       <span class="ruby-identifier">height</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">width</span>
47:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>